package twoPhase;

public class TwoParse {

    private volatile boolean stopFlag = false;

    private Thread monitor;

    public void start() {
        Runnable runnable = () -> {
            while (true) {
                if (stopFlag) {
                    System.out.println("正在加快速度");
                    break;
                }
                try {
                    System.out.println("正在办事");
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
            System.out.println("已经完事");
        };
        monitor = new Thread(runnable, "t1");
        monitor.start();
    }

    public void stop() {
        System.out.println("请您快点完事");
        stopFlag = true;
        monitor.interrupt();
    }

}
